package com.abc.controller.web;

import com.abc.dao.ExampleMapper;
import com.abc.entity.Example;
import com.abc.vo.ExampleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/case")
public class CaseController {

    @Autowired
    ExampleMapper exampleMapper;


    @GetMapping("")
    public String caseTremplate(ModelMap map) {
        List<ExampleVo> list = exampleMapper.findExampleListWithImage();
        map.addAttribute("list", list);
        return "case";
    }

    @GetMapping("/{lowerCase}")
    public String detail(@PathVariable String lowerCase, ModelMap map) {
        map.addAttribute("lowerCase", lowerCase);
        Example q = new Example();
        q.setLowerCase(lowerCase);
        List<Example> list = exampleMapper.queryExample(q);
        if (list.isEmpty()) {
            return "404";
        }
        map.addAttribute("detail", list.get(0));
        return "detail";
    }
}
